﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using EARS.App_Code;

namespace EARS
{
    public partial class MasterPage : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (HttpContext.Current.User.Identity.IsAuthenticated)
            {
                pnlLogin.Visible = false;
                pnlLogout.Visible = true;
                Account a = new Account();
                lblUser.Text = a.GetNameByID(HttpContext.Current.User.Identity.Name);
            }
            else if (this.Parent.ToString().Equals("ASP.login_aspx"))
            {
                pnlLogin.Visible = false;
                pnlLogout.Visible = false;
            }
            else
            {
                pnlLogout.Visible = false;
                pnlLogin.Visible = true;
            }
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            Account a = new Account();
            bool check = a.Login(txtUserID.Text, txtPassword.Text);
            if (check == true)
            {
                FormsAuthentication.RedirectFromLoginPage(txtUserID.Text, false);
            }
            else
            {
                lblError.Text = "Incorrect User ID & Password. Please try again.";
            }
        }

        protected void btnForgetPassword_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/ForgetPassword.aspx");
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            Session["SearchText"] = txtSearch.Text;
            Response.Redirect("~/SearchResult.aspx");
        }

        protected void btnCreate_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/CreateAccount.aspx");
        }

        protected void btnChangePassword_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Protected/ChangePassword.aspx");
        }

        protected void btnLogout_Click(object sender, EventArgs e)
        {
            FormsAuthentication.SignOut();
            Response.Redirect("~/Home.aspx");
        }
    }
}